package com.account.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.account.validate.LoginValidator;

//@WebServlet("/Authentication")
public class Authentication extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public Authentication() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		       String radiobutton = request.getParameter("radiobutton");
		       String username = request.getParameter("username");
		       String password = request.getParameter("password");
		       PrintWriter out = response.getWriter();
		       response.setContentType("text/html");
		       LoginValidator loginValidator = new LoginValidator();
		       
		       
		       if((loginValidator.isValidate(username))&&(loginValidator.isPassword(password))){
		    	   RequestDispatcher dispatcher = request.getRequestDispatcher("/admin.html");
		    	   dispatcher.forward(request, response);
		       }else{
		    	   out.print("invalid login");

		    	   RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/login.jsp");

		    	   dispatcher.include(request, response);
		       }
		       
	}

}
